//
//  RBGActualiteDetailController.m
//  BateauGenerique
//
//  Created by Kevin De Jesus Ferreira on 24/05/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "RBGActualiteDetailController.h"
#import "RBGAppDelegate.h"
#import "RBGNavigationBar.h"
#import "RBGColorManager.h"
#import "UIImageView+WebCache.h"

@interface RBGActualiteDetailController (){
    RBGAppDelegate *appDelegate;
}


@end

@implementation RBGActualiteDetailController


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self charger];
    [self remplir];
    [self positionnerVue];
    [self chargerCouleur];
}

-(void) charger
{
    appDelegate = (RBGAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    
    // On rend le text view scrollable
    [self.descriptionActualite setUserInteractionEnabled:YES];

}

-(void) remplir
{
    [self setTitle:self.actualite.title];
    
    
    [RBGNavigationBar customNavigationBar:self.navigationController andTitle:@"Titre de l'actualité" andBackgroundColor:appDelegate.donnees.parametres.backgroundColorUn andTextColor:appDelegate.donnees.parametres.fontColorUn];
    
    self.descriptionActualite.backgroundColor = [UIColor clearColor];
    
    [self.imageActualite setImageWithURL:[NSURL URLWithString:self.actualite.imageAdress]];
    [self.fond setImageWithURL:[NSURL URLWithString:appDelegate.donnees.parametres.imageFond]];
    
    [self.descriptionActualite setText:self.actualite.description];
    [self.titreActualite setText:self.actualite.title];
    [self.date setText:self.actualite.dateFormattee];

}

-(void) positionnerVue
{
    
    [self.imageActualite setFrame:CGRectMake(0, 35, 320, 282)];
    
    [self.donneesActualites setFrame:CGRectMake(10, self.imageActualite.frame.origin.y + self.imageActualite.frame.size.height, self.donneesActualites.frame.size.width, self.donneesActualites.frame.size.height)];
    
    [self.descriptionActualite setFrame:CGRectMake(self.descriptionActualite.frame.origin.x, self.descriptionActualite.frame.origin.y, self.descriptionActualite.frame.size.width, self.descriptionActualite.frame.size.height)];

    
    [self.descriptionActualite sizeToFit];
        self.scrollView.contentSize = CGSizeMake(320, self.donneesActualites.frame.size.height + self.donneesActualites.frame.origin.y);
}


-(void) chargerCouleur
{
    
    self.navigationController.navigationBar.topItem.title = @"";
    
    [RBGColorManager changeTextColorSubViews:self.donneesActualites withColor:appDelegate.donnees.parametres.fontColorDeux];
    
    [self.reveil setImage:[RBGColorManager colorImageWithColor:appDelegate.donnees.parametres.fontColorDeux andImage:self.reveil.image]];
    
}


@end
